package com.example.lib_common.util;

import androidx.lifecycle.MutableLiveData;

import java.util.HashMap;
import java.util.Map;

public class LiveDataManager  {

    private static LiveDataManager liveDataManager = new LiveDataManager();
    //装载所有管子得容器
    private Map<String, MutableLiveData<Object>> map;

    private LiveDataManager(){
        map = new HashMap<>();
    }

    public boolean isContainKey(String key){
        return map.containsKey(key);
    }

    public static LiveDataManager getInstance(){
        return liveDataManager;
    }

    /**
     * 存取一体
     * @param key
     * @param cla
     * @param <T>
     * @return
     */
    public<T> MutableLiveData<T> with(String key,Class<T> cla){
        if (!map.containsKey(key)){
            map.put(key,new MutableLiveData<Object>());
        }

        return (MutableLiveData<T>) map.get(key);
    }
}
